home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 May / SGI IRIX 6.5 Applications 2004 May.iso / dev / java_dev.idb / usr / java / include / irix / sysmacros_md.h.z / sysmacros_md.h
Encoding:
C/C++ Source or Header  |  2000-05-20  |  5.1 KB  |  168 lines

  1. /*
  2.  * @(#)sysmacros_md.h    1.17 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. #ifndef _SOLARIS_SYSMACROS_MD_H_
  16. #define _SOLARIS_SYSMACROS_MD_H_
  17.  
  18. /*
  19.  * Because these are used directly as function ptrs, just redefine the name
  20.  */
  21. #define sysMalloc    malloc
  22. #define sysFree        free
  23. #define sysCalloc    calloc
  24. #define sysRealloc    realloc
  25.  
  26. /* A macro for sneaking into a sys_mon_t to get the owner sys_thread_t */
  27. #define sysMonitorOwner(mid)   ((mid)->monitor_owner)
  28.  
  29. #ifdef DEBUG
  30. extern void DumpThreads(void);
  31. void panic (const char *, ...);
  32. #if defined(JAVA) && !defined(NATIVE)
  33. #define sysAssert(expression) {        \
  34.     if (!(expression)) {        \
  35.     if (SCHED_LOCKED())  SCHED_UNLOCK(); \
  36.     DumpThreads();            \
  37.     panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
  38.     }                    \
  39. }
  40. #else /* !(defined(JAVA) && !defined(NATIVE)) */
  41. #define sysAssert(expression) {        \
  42.     if (!(expression)) {        \
  43.     DumpThreads();            \
  44.     panic("\"%s\", line %d: assertion failure\n", __FILE__, __LINE__); \
  45.     }                    \
  46. }
  47. #endif /* !(defined(JAVA) && !defined(NATIVE)) */
  48. #else
  49. #define sysAssert(expression) 0
  50. #endif
  51.  
  52. /*
  53.  * Check whether an exception occurred.  This also gives us the oppor-
  54.  * tunity to use the already-required exception check as a trap for other
  55.  * system-specific conditions.
  56.  */
  57. #define sysCheckException(ee) \
  58.     if (!exceptionOccurred(ee)) { \
  59.        continue; \
  60.     }
  61.  
  62. /*
  63.  * Case insensitive compare of ASCII strings
  64.  */
  65. #define sysStricmp(a, b)        strcasecmp(a, b)
  66.  
  67. /*
  68.  * File system macros
  69.  */
  70. #define sysOpen(_path, _oflag, _mode)    open(_path, _oflag, _mode)
  71. #define sysRead(_fd, _buf, _n)        read(_fd, _buf, _n)
  72. #define sysWrite(_fd, _buf, _n)        write(_fd, _buf, _n)
  73. #define sysClose(_fd)            close(_fd)
  74. #define sysAccess(_path, _mode)        access(_path, _mode)
  75. #define sysStat(_path, _buf)        stat(_path, _buf)
  76. #define sysMkdir(_path, _mode)        mkdir(_path, _mode)
  77. #define sysUnlink(_path)        unlink(_path)
  78. #define sysIsAbsolute(_path)        (*(_path) == '/')
  79. #define sysCloseDir(_dir)        closedir(_dir)
  80. #define sysOpenDir(_path)        opendir(_path)
  81. #define sysRmdir(_dir)                  remove(_dir)
  82. #define sysNativePath(path)            (path) 
  83. #define sysSeek(fd, offset, whence)    lseek(fd, offset, whence)
  84. #define sysRename(s, d)            rename(s, d)
  85.  
  86. /*
  87.  * Set up thread-local storage for second order monitor cache.  The
  88.  * number of words of thread-local storage must be a power of 2!
  89.  */
  90. #define SYS_TLS_MONCACHE 8 /* must be power of 2 */
  91. #define sysCurrentCacheKey(tid) (tid->cacheKey)
  92. #define sysLocalMonCache(tid, hash) (tid->monitorCache[hash])
  93.  
  94. /*
  95.  * Solaris always runs in Total Store Order mode for Sparc and
  96.  * Intel doesn't seem to support a weak consistency model for MP
  97.  * so we define this to do nothing.
  98.  */
  99. #define sysStoreBarrier() 0
  100.  
  101. /*
  102.  * Simple, fast recursive lock for the monitor cache.
  103.  *
  104.  * This is threads package specific, whereas sysmacros.h is not, but
  105.  * could be simplified if sysmacros.h ever specializes.
  106.  * 
  107.  * The includes for threads package-specific files are ugly here because
  108.  * this file goes into javah, which doesn't otherwise include from those
  109.  * directories.
  110.  *
  111.  * Let's face it...we need threads package-specific sys include files.
  112.  */
  113. #ifndef NATIVE
  114.  
  115. #include "../green_threads/include/schedule.h"
  116. #define sysCacheLockInit()     /* A no-op */
  117. #define sysCacheLock()        SCHED_LOCK()
  118. #define sysCacheLocked()    SCHED_LOCKED()
  119. #define sysCacheUnlock()    SCHED_UNLOCK()
  120.  
  121. /* Override the extern in sys_api.h with something faster */
  122. #define sysThreadSelf()        greenThreadSelf()
  123.  
  124. #define sysMemoryFlush() 0
  125. #define sysIsMP() 0
  126.  
  127. #else
  128.  
  129. #if defined(_COMPILER_VERSION) && (_COMPILER_VERSION>=700)
  130. #define sysMemoryFlush() __synchronize()
  131. #endif
  132.  
  133. #include "../native_threads/include/mutex_md.h"
  134.  
  135. typedef struct {
  136.     mutex_t mutex;
  137.     long entry_count;
  138.     sys_thread_t *owner;
  139. } cache_lock_t;
  140.  
  141. /*
  142.  * We do leave the mutex locked across the whole cache lock to avoid
  143.  * the extra unlock and lock that a smaller critical region would entail.
  144.  */
  145. extern cache_lock_t _moncache_lock;
  146. #define sysCacheLockInit() {   mutexInit(&_moncache_lock.mutex);    \
  147.                    _moncache_lock.entry_count = 0;        \
  148.                    _moncache_lock.owner = 0;        \
  149.                }
  150. #define sysCacheLock()     {   mutexLock(&_moncache_lock.mutex);    \
  151.                    sysAssert(_moncache_lock.entry_count >= 0);\
  152.                    if (_moncache_lock.entry_count++ == 0) {    \
  153.                   _moncache_lock.owner = sysThreadSelf();\
  154.                    }                    \
  155.                }
  156. /* Should not need locking: */
  157. #define sysCacheLocked()   (_moncache_lock.owner == sysThreadSelf())
  158. #define sysCacheUnlock()   {   sysAssert(_moncache_lock.entry_count > 0);\
  159.                    if (--_moncache_lock.entry_count == 0) {    \
  160.                   _moncache_lock.owner = 0;        \
  161.                    }                    \
  162.                    mutexUnlock(&_moncache_lock.mutex);    \
  163.                }
  164.  
  165. #endif /* NATIVE */
  166.  
  167. #endif /*_SOLARIS_SYSMACROS_MD_H_*/
  168.